/*************************************************************************
 * Filename:    QueueManager.h
 * Description: Manages the various process queues.
 * Group 2:     nachOS
 * Authors:     Ying Wang
 *              Daniel Fairweather
 * Class:       CSE 325
 * Instructor:  Mr. Duggan
 * Assignment:  Lab #3 Scheduler
 * Assigned:    Feburary 12, 2013
 * Due:         Feburary 26, 2013
 *************************************************************************/
#ifndef QUEUEMANAGER_H
#define QUEUEMANAGER_H
#include "ProcessManager.h"
#define NUM_QUEUES 5



/**
 * The following numbers (Queue IDs) should be used to identify queues.
 * 0 New        Holds newly created processes.
 * 1 Ready      Processes which are waiting to be executed.
 * 2 Running    Processes which are currently being executed.
 * 3 Waiting    Holds processes which are waiting on I/O.
 * 4 Terminated Processes which are ready to be terminated.
 */



/**
 * A queue of process control blocks.
 */
typedef struct process_queue_s{
    process_control_block* head;       /* The first process control block in the queue. */
    process_control_block* tail;       /* The last process control block in the queue. */
} process_queue;



process_queue queues[NUM_QUEUES]; /* The process queues which represent various states (See .h for more info) */



/**
 * Initializes all of the queues within QueueManager.
 * NOTE: Does not free any of the process control blocks!
 * @author Daniel Fairweather
 */
void initalizeQueueManager();



/**
 * Enqueues a process.
 * @author Daniel Fairweather
 * @param qid The queue id of the queue to preform the operation on.
 * @param The process to enqueue.
 * @returns process_control_block* The process that was dequeued.
 */
process_control_block* enqueue(int qid, process_control_block* process);



/**
 * Dequeues a process.
 * @author Daniel Fairweather
 * @param qid The queue id of the queue to preform the operation on.
 * @param pid The process id of the process to dequeue.
 * @returns process_control_block* The process that was dequeued.
 */
process_control_block* dequeue(int qid);



/**
 * Deletes a process.
 * @author Daniel Fairweather
 * @param qid The queue id of the queue to preform the operation on.
 * @param pid The process id of the process to delete.
 * @returns process_control_block* The process that was deleted.
 */
process_control_block* delqueue(int qid, int pid);



/**
 * Searches for a process.
 * @author Daniel Fairweather
 * @param qid The queue id of the queue to preform the operation on.
 * @param pid The process id of the process to search for.
 * @returns process_control_block* The process that was found.
 */
process_control_block* search(int qid, int pid);



/**
 * Determines if a PID is unique among all queues.
 * @author Daniel Fairweather
 * @param qid The queue id of the queue to preform the operation on.
 * @param pid The process id of the process to search for.
 * @returns int 0 if the pid is not unique, 1 if it is.
 */
int isUniquePID(int pid);



/**
 * Determines if a queue is empty.
 * @author Daniel Fairweather
 * @param qid The queue id of the queue to check.
 * @returns int 0 if the queue is not empty, 1 if the queue is empty.
 */
int isEmptyQueue(int qid);



/**
 * Getter for a specific queue
 * @author Jan Durakiewicz
 */
process_queue* getQueue(int qid);



#endif